<?php

namespace meeting;

use think\Db;
use think\facade\Config;

class HuaweiMeeting
{
    const API_TYPE = "华为云会议API";
    const TABLE_LOG = 'b_api_log';
    const MEETING_HOST = 'https://api.meeting.huaweicloud.com';

    const HW_MEETING_MEDIATYPES = 'HDVideo';
    const HW_MEETING_SENDNOTIFY = 0;
    const HW_MEETING_ISAUTORECORD = 0; //会议是否自动启动录制，1：自动启动录制，0：不自动启动录制
    const HW_MEETING_RECORDTYPE = 2;
    const HW_MEETING_RECORDAUXSTREAM = 0; //辅流是否录制，0不录制，1录制;
    const HW_MEETING_RECORDAUTHTYPE = 0;

    public function __construct() {

    }
    /**
     * 华为云会议管理登录
     */
    public function meetingLogin()
    {
        $tokenInfo=Db::name('b_thirdapp_token')->where("expire_time",">",now_time())->where('type','huawei_meeting')->order(['expire_time' => 'desc'])->find();
        if($tokenInfo){
            return $tokenInfo['token'];
        }
        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/acs/auth/account";
        $method = "POST";
        //头部信息
        $headers = array();
        $account=Config::get('system.huawei_meeting_account');
        array_push($headers, "Authorization:Basic " . base64_encode($account.":".Config::get('system.huawei_meeting_password')));
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
        //post信息
        $bodys=json_encode(['account'=>$account,'clientType'=>72]);
        //curl
        $returnInfo=$this->huweiCurl($path,$method,$headers,$host,$bodys);
        if($returnInfo['status']==1){
            $insterData=['id'=>guid(),"create_datetime"=>now_time(),'type'=>'huawei_meeting','expire_time'=>$returnInfo['data']['expireTime'],'token'=>$returnInfo['data']['accessToken']];
            Db::name('b_thirdapp_token')->insert($insterData);
            return $returnInfo['data']['accessToken'];
        }
        //看能否做个重试处理
        return null;

    }

    /**
     * 华为云用户管理登录
     */
    public function manageLogin()
    {
        $tokenInfo=Db::name('b_thirdapp_token')->where("expire_time",">",now_time())->where('type','huawei_manage')->order(['expire_time' => 'desc'])->find();
        if($tokenInfo){
            return $tokenInfo['token'];
        }
        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/acs/auth/account";
        $method = "POST";
        //头部信息
        $headers = array();
        $account=Config::get('system.huawei_manage_account');
        array_push($headers, "Authorization:Basic " . base64_encode($account.":".Config::get('system.huawei_manage_password')));
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
        //post信息
        $bodys=json_encode(['account'=>$account,'clientType'=>0]);
        //curl
        $returnInfo=$this->huweiCurl($path,$method,$headers,$host,$bodys);
        if($returnInfo['status']==1){
            $insterData=['id'=>guid(),"create_datetime"=>now_time(),'type'=>'huawei_manage','expire_time'=>$returnInfo['data']['expireTime'],'token'=>$returnInfo['data']['accessToken']];
            Db::name('b_thirdapp_token')->insert($insterData);
            return $returnInfo['data']['accessToken'];
        }
        return null;
    }

    /**
     * 查看用户云会议室
     * @param $token
     * @param $urlData
     * @return array|\think\response\Json
     */
    public function viewVmr($token, $urlData, $type ='member')
    {

        //$type = //member个人，corp企业
        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/".$type."/vmr";
        $method = "GET";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }

    /**
     * 华为云新建会议
     */
    public function createConferences($token,$inputData,$meetingid =null)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/mmc/management/conferences";
        $method = "POST";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $inputData['mediaTypes']=self::HW_MEETING_MEDIATYPES;
        $inputData['sendNotify']=self::HW_MEETING_SENDNOTIFY;
        $inputData['isAutoRecord']=self::HW_MEETING_ISAUTORECORD;
        $inputData['recordType']=self::HW_MEETING_RECORDTYPE;
        $inputData['vmrFlag']=1; //?
        $inputData['vmrID']= $this->getVmridByMeetingid($meetingid);//?
        $inputData['recordAuxStream']=self::HW_MEETING_RECORDAUXSTREAM; //开启录制
        $inputData['recordAuthType']=self::HW_MEETING_RECORDAUTHTYPE;   //获取到链接，点链接即可观看/下载
        $inputData['confConfigInfo']=['isSendSms'=>false,'vmrIDType'=>'1'];             //不发送短信
        $bodys=json_encode($inputData);

        //curl
        $returnInfo = $this->huweiCurl($path,$method,$headers,$host,$bodys);
        if($returnInfo['status']==1){
            $returnInfoData = $returnInfo['data'][0];
            $insterData=[
                'id'=>guid(),
                'meetingid'=>$meetingid,
                "create_datetime"=>now_time(),
                'conferenceid'=>$returnInfoData['conferenceID'],
                'chairpwd'=>$returnInfoData['passwordEntry'][0]['password'],
                'generalpwd'=>$returnInfoData['passwordEntry'][1]['password'],
                'guest_joinuri'=>$returnInfoData['guestJoinUri'],
                'chair_joinuri'=>$returnInfoData['chairJoinUri'],
                'attendee'=>$returnInfoData['partAttendeeInfo'],
                'deptname'=>$returnInfoData['deptName'],
                'data'=>json_encode($returnInfoData)
            ];
            Db::name('b_hw_conference')->insert($insterData);
        }
        return $returnInfo;
    }
    /**
     * 华为云取消会议
     */
    public function cancelConferences($token,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/mmc/management/conferences?".http_build_query($urlData);
        $method = "DELETE";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }

    /**
     * 华为云编辑会议
     */
    public function editConferences($token,$inputData,$urlData,$meetingid)
    {
        //将所有inputData读取--开始
        $meeting = Db::name('v_meeting')->where("id",$meetingid)->find();
        $caseno_desc = Db::name('c_case')->where('id', '=', $meeting['caseid'])->value('caseno_desc');

        //创建华为云会议
        $begin_datetime = $meeting['begin_datetime'];
        $end_datetime = $meeting['end_datetime'];
        $use = $meeting['use'];

        $inputData['startTime']=date('Y-m-d H:i',$begin_datetime-8*3600);
        $inputData['subject'] =$caseno_desc.$use;
        $inputData['length'] = ($end_datetime-$begin_datetime)/60; //会议时长
        //将所有inputData读取--结束

        $inputData['mediaTypes']=self::HW_MEETING_MEDIATYPES;
        $inputData['sendNotify']=self::HW_MEETING_SENDNOTIFY;
        $inputData['isAutoRecord']=self::HW_MEETING_ISAUTORECORD;
        $inputData['recordType']=self::HW_MEETING_RECORDTYPE;
        $inputData['vmrFlag']=1; //?
        $inputData['vmrID']=$this->getVmridByMeetingid($meetingid); //?
        $inputData['recordAuxStream']=self::HW_MEETING_RECORDAUXSTREAM; //开启录制
        $inputData['recordAuthType']=self::HW_MEETING_RECORDAUTHTYPE;   //获取到链接，点链接即可观看/下载
        $inputData['confConfigInfo']=['isSendSms'=>false, 'vmrIDType'=>'1'];             //不发送短信，随机密码
        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/mmc/management/conferences?".http_build_query($urlData);
        $method = "PUT";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息

        $bodys=json_encode($inputData);

        //curl

        $returnInfo = $this->huweiCurl($path,$method,$headers,$host,$bodys);
        if($returnInfo['status']==1){
            $returnInfoData = $returnInfo['data'][0];
            $updateData=[
                'conferenceid'=>$returnInfoData['conferenceID'],
                'chairpwd'=>$returnInfoData['passwordEntry'][0]['password'],
                'generalpwd'=>$returnInfoData['passwordEntry'][1]['password'],
                'guest_joinuri'=>$returnInfoData['guestJoinUri'],
                'chair_joinuri'=>$returnInfoData['chairJoinUri'],
                'attendee'=>$returnInfoData['partAttendeeInfo'],
                'deptname'=>$returnInfoData['deptName'],
                'data'=>json_encode($returnInfoData)
            ];
            Db::name('b_hw_conference')->where("meetingid",$meetingid)->update($updateData);
        }
        return $returnInfo;
    }
    /**
     * 华为云查看会议
     */
    public function viewConferences($token,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/mmc/management/conferences/confDetail?".http_build_query($urlData);
        $method = "GET";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 华为云查看历史会议
     */
    public function viewHistoryConferences($token,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/mmc/management/conferences/history/confDetail?".http_build_query($urlData);
        $method = "GET";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 华为云查看会议
     */
    public function viewRecord($token,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/mmc/management/conferences/record/files?".http_build_query($urlData);
        $method = "GET";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }

    /**
     * 华为云APPID鉴证
     */
    public function appAuth($token,$inputData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v2/usg/acs/auth/appauth";
        $method = "POST";
        //头部信息
        $headers = array();
        array_push($headers, "Authorization:HMAC-SHA256 signature=" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息

        $bodys=json_encode($inputData);

        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 华为云新建用户
     */
    public function createMember($token,$inputData,$accountid)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/member";
        $method = "POST";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $inputData['sendNotify']=0;
        $inputData['hidePhone']  = "true";

        $bodys=json_encode($inputData);

        //curl
        $returnInfo=$this->huweiCurl($path,$method,$headers,$host,$bodys);
        if($returnInfo['status']==1){
            $insterData=[
                'id'=>guid(),
                'accountid'=>$accountid,
                'create_datetime'=>now_time(),
                'huwei_id'=>$returnInfo['data']['id'],
                'account'=>$returnInfo['data']['userAccount'],
                'name'=>$returnInfo['data']['name'],
                'phone'=>$returnInfo['data']['phone'],
                'email'=>$returnInfo['data']['email'],
                'sipnum'=>$returnInfo['data']['sipNum'],//软终端号，用于会议人员创建的关联
                'admin_type'=>$returnInfo['data']['adminType'],
                'data'=>json_encode($returnInfo['data'])];
            Db::name('b_hw_account')->insert($insterData);
        }
        return $returnInfo;
    }
    /**
     * 华为云批量删除用户
     */
    public function delMember($token,$inputData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/member/delete";
        $method = "POST";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息

        $bodys=json_encode($inputData);

        //curl
        $returnInfo = $this->huweiCurl($path,$method,$headers,$host,$bodys);
        //把我们系统的华为云用户删除
        Db::name('b_hw_account')->where("account","in",$inputData)->delete();

        return $returnInfo;    }
    /**
     * 华为云编辑会议
     */
    public function editMember($token,$inputData,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/member/".$urlData['account'];
        $method = "PUT";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息

        $bodys=json_encode($inputData);

        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 华为云查看用户
     */
    public function viewMember($token,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/member/".$urlData['account'];
        $method = "GET";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 华为云分页查询用户
     */
    public function listMember($token,$urlData)
    {
        // $urlData=["offset"=>1,"limit"=>"10"];
        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/member?limit=".$urlData['limit']."&offset=".$urlData['offset'];
        $method = "GET";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode([]);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 华为云新建部门
     */
    public function createDept($token,$inputData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/dept";
        $method = "POST";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息

        $bodys=json_encode($inputData);

        //curl
        $returnInfo=$this->huweiCurl($path,$method,$headers,$host,$bodys);

        if($returnInfo['status']==1){
            $insterData=['id'=>guid(),"create_datetime"=>now_time(),'name'=>$inputData['deptName'],'code'=>$returnInfo['data']['value'],'data'=>json_encode($inputData)];
            Db::name('b_hw_dept')->insert($insterData);
        }
        return $returnInfo;
    }
    /**
     * 华为云删除部门
     */
    public function delDept($token,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/dept/".$urlData['dept_code'];
        $method = "DELETE";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 华为云编辑会议
     */
    public function editDept($token,$inputData,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/dept/".$urlData['dept_code'];
        $method = "PUT";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息

        $bodys=json_encode($inputData);

        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 华为云查看会议
     */
    public function viewDept($token,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/member/dept/".$urlData['dept_code'];
        $method = "GET";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 华为云增加终端
     */
    public function addDevice($token,$inputData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/device";
        $method = "POST";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");


        $bodys=json_encode($inputData);

        //curl
        $returnInfo = $this->huweiCurl($path,$method,$headers,$host,$bodys);

        return $returnInfo;
    }
    /**
     * 华为云查看终端
     */
    public function viewDevice($token,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/corp/device/".$urlData['sn'];
        $method = "GET";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /*
     * 华为云会议curl访问
     */
    private function huweiCurl($path,$method,$headers,$host,$bodys){
        //curl
        $runNumber=0;
        RUNCODE:
        $url = $host . $path;
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, true);
        if (1 == strpos("$".$host, "https://"))
        {
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
        //返回数据
        $result = curl_exec($curl);
        //截取返回字符串
        $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
        $rbody = substr($result, $header_size);
        //记录日志

        $this->log($bodys,$rbody,$path,$headers);
        //是否获取成功
        $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
        $output = json_decode($rbody, true);
        if($httpCode == 200) {
            return array_info("操作成功",$output,1);

        }else{
            if(isset($output['error_code']) && ($output['error_code']=='MMC.118000001'
                    || $output['error_code']=='USG.000000004'
                    || $output['error_code']=='WSS.000000004')){
                $token="";
                foreach($headers as $headerKey=>$headerValue){
                    if(strpos($headerValue, "X-Access-Token:") === 0){
                        $token=substr($headerValue, 15);
                        unset($headers[$headerKey]);
                    }
                }
                $type=Db::name('b_thirdapp_token')->where("token",$token)->value('type');

                $typeLogin=substr($type,7)."Login";
                Db::name('b_thirdapp_token')->where("token",$token)->update(['expire_time'=>now_time()]);
                $tokenInfo=$this->$typeLogin();
//                if(isset($tokenInfo['data']['accessToken'])){
//                    $tokenInfo['data']['token']=$tokenInfo['data']['accessToken'];
//                }
                if($runNumber==0){
                    array_push($headers, "X-Access-Token:" . $tokenInfo);
                    $runNumber++;
                    goto RUNCODE;
                }

            }
            if(isset($output['error_code'])){
                $pattern = array('.');
                $replace = array('');
                $errorCode=str_replace($pattern, $replace, $output['error_code']);

                $output['error_msg']=Config::get('huwei_error.'.$errorCode)?"(".Config::get('huwei_error.'.$errorCode).")":"";
            }
            return array_info('操作失败',$output);
        }
    }

    private function getVmridByMeetingid($meetingid){
        $vmrid = Db::name('v_meeting')->alias('m')
            ->join('c_hearingroom h', 'h.id=m.hearingroomid')
            ->where("m.id",'=', $meetingid)->value('vmrid');

        if(!$vmrid){
            $vmrid = Config::get('system.huawei_vmr_id');
        }
        return $vmrid;
    }

    /*
     * 日志
     */
    private function log($com, $result,$path,$headers=[]){
        $data['id'] = guid();
        $data['create_datetime'] = now_time();
        $data['api'] = self::API_TYPE."/".$path;
        $data['input']= $com;
        $data['result']= $result;
        // $data['headers']= json_encode($headers);
        Db::name(self::TABLE_LOG)->insert($data);

    }

    /**
     * 华为云新建网络研讨会
     */
    public function createWebinar($token,$inputData,$meetingid =null)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/wss/webinar/open/conferences";
        $method = "POST";
        //头部信息
        $requestId=guid();
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "X-Request-Id:" . $requestId);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        //  $inputData['vmrID']= $this->getVmridByMeetingid($meetingid);//
        $inputData['vmrID']   = Config::get('system.huawei_vmr_id'); //?

        $inputData['timeZoneId']= "26";//
        $inputData['scope']= 1;//
        //是否发送通知
        $inputData['notifySetting']=['enableEmail'=>"N",'enableSms'=>'N','enableCalendar'=>'N'];

        $bodys=json_encode($inputData);

        //curl
        $returnInfo = $this->huweiCurl($path,$method,$headers,$host,$bodys);
        if($returnInfo['status']==1){
            $returnInfoData = $returnInfo['data'];
            $insterData=[
                'id'=>guid(),
                'meetingid'=>$meetingid,
                "create_datetime"=>now_time(),
                'conferenceid'=>$returnInfoData['conferenceId'],
                'chairpwd'=>$returnInfoData['chairPasswd'],
                'generalpwd'=>$returnInfoData['guestPasswd'],
                'audiencepwd'=>$returnInfoData['audiencePasswd'],
                'guest_joinuri'=>$returnInfoData['guestJoinUri'],
                'chair_joinuri'=>$returnInfoData['chairJoinUri'],
                'audience_joinuri'=>$returnInfoData['audienceJoinUri'],
                'attendee'=>$returnInfoData['attendees'],
                'deptname'=>$returnInfoData['deptName'],
                'data'=>json_encode($returnInfoData)
            ];
            Db::name('b_hw_conference')->insert($insterData);
        }
        return $returnInfo;
    }
    /**
     * 华为云编辑网络研讨会
     */
    public function editWebinar($token,$inputData,$urlData,$meetingid=null)
    {
        //将所有inputData读取--开始
        $meeting = Db::name('v_meeting')->where("id",$meetingid)->find();
        $caseno_desc = Db::name('c_case')->where('id', '=', $meeting['caseid'])->value('caseno_desc');

        //创建华为云会议
        $begin_datetime = $meeting['begin_datetime'];
        $end_datetime = $meeting['end_datetime'];
        $use = $meeting['use'];

        $inputData['startTime']=date('Y-m-d H:i',$begin_datetime-8*3600);
        $inputData['subject'] =$caseno_desc.$use;
        $inputData['duration'] = ceil(($end_datetime-$begin_datetime)/60); //会议时长
        //将所有inputData读取--结束
        $inputData['timeZoneId']= 26;//
        $inputData['scope']= 1;//
        //是否发送通知
        $inputData['notifySetting']=['enableEmail'=>"N",'enableSms'=>'N','enableCalendar'=>'N'];

        $inputData['vmrID']=$this->getVmridByMeetingid($meetingid); //?
        $inputData['conferenceId']=$urlData['conferenceID']; //?

        //域名`
        $host = self::MEETING_HOST;
        $path = "/v1/wss/webinar/open/conferences";
        $method = "PUT";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息

        $bodys=json_encode($inputData);

        //curl

        $returnInfo = $this->huweiCurl($path,$method,$headers,$host,$bodys);

        return $returnInfo;
    }
    /**
     * 华为云取消网络研讨会
     */
    public function cancelWebinar($token,$urlData)
    {

        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/wss/webinar/open/conferences/".$urlData['conferenceID'];
        $method = "DELETE";
        //头部信息
        $headers = array();
        array_push($headers, "X-Access-Token:" . $token);
        //    array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode([]);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
    /**
     * 查看自己的信息
     * @param $token
     * @param $urlData
     * @return array|\think\response\Json
     */
    public function viewMeMember($token, $urlData, $type ='member')
    {

        //$type = //member个人，corp企业
        //域名
        $host = self::MEETING_HOST;
        $path = "/v1/usg/dcs/member";
        $method = "GET";
        //头部信息
        $requestId=guid();
        $headers = array();

        array_push($headers, "X-Access-Token:" . $token);
        array_push($headers, "X-Request-Id:" . $requestId);
        array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");

        //post信息
        $bodys=json_encode($urlData);
        //curl
        return $this->huweiCurl($path,$method,$headers,$host,$bodys);
    }
}
